<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>composePromise</title>
</head>

<body>
    <div>打开控制台查看结果</div>
    <script>
        const composePromise =
            (...fns) =>
                x =>
                    fns.reduce((promise, fn) => promise.then(fn), Promise.resolve(x));
        function addTwo(x) {
            return x + 2;
        }
        function addThree(x) {
            return x + 3;
        }
        function addFive(x) {
            return x + 5;
        }
        let addTen = composePromise(addTwo, addThree, addFive);
        addTen(8).then(console.log); // 18
    </script>
</body>

</html>